
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>

<%
    // 获取用户提交的反馈信息
    String name = request.getParameter("name");
    String email = request.getParameter("email");
    String rating = request.getParameter("rating");
    String category = request.getParameter("category");
    String message = request.getParameter("message");

    // 数据库连接信息（请根据实际情况修改）
    String url = "jdbc:mysql://localhost:3306/educate";
    String dbUser = "root";
    String dbPassword = "123456";

    try {
        // 加载数据库驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        // 建立数据库连接
        Connection conn = DriverManager.getConnection(url, dbUser, dbPassword);

        // 插入反馈数据到数据库
        String sql = "INSERT INTO feedback (name, email, rating, category, message, submit_time) VALUES (?, ?, ?, ?, ?, NOW())";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, name);
        pstmt.setString(2, email);
        pstmt.setString(3, rating);
        pstmt.setString(4, category);
        pstmt.setString(5, message);

        int result = pstmt.executeUpdate();
        if (result > 0) {
            out.println("<script>alert('反馈提交成功！'); location.href='feedback.jsp';</script>");
        } else {
            out.println("<script>alert('反馈提交失败，请重试！'); location.href='feedback.jsp';</script>");
        }

        // 关闭数据库连接
        pstmt.close();
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
        out.println("<script>alert('反馈提交失败，请重试！'); location.href='feedback.jsp';</script>");
    }
%>
